/**
 * Created by chaoCheng on 2017/1/13.
 */
function GroupController(
    $uibModal,
    $log,
    Detail,
    $scope,
    $state,
    $stateParams
) {
    var vm=this
    vm.planId=$stateParams.planId;
    vm.queryParams = _.clone($stateParams);
    Detail.searchGroup({
        planId: vm.planId,
        groupName:vm.queryParams.groupName,
    }).$promise.then(function(response){
        vm.groups = response.content
    })
    vm.cancel= function(){
        $state.go('detail', {'planId':$stateParams.planId})
    }
    vm.addgroup = function($index) {
           Detail.addGroup({
                    planId: $stateParams.planId,
                    groupId:vm.groups[$index].id
            }).$promise.then(function(response){
                if(response.success != null){
                   // $state.go('detail', {'planId':$stateParams.planId});
                    // $state.go('groupSearch' , {'planId':$stateParams.planId})
                    vm.groups.splice($index,1);
                }else {
                    alert("添加失败！");
                }
            })
    }
    vm.searchGroup = function (){
        Detail.searchGroup({
            planId: vm.planId,
            groupName:vm.queryParams.groupName,
        }).$promise.then(function(response){
            vm.groups = response.content
            })
    }
    }